<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	pageContext.setAttribute("path",request.getContextPath());
%>
 <%@ taglib uri = "http://ckfinder.com" prefix="ckf" %>
 <%@ taglib uri="http://ckeditor.com" prefix="ck" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<html>
	<head>
		<base href="<%=basePath%>">

		<title>修改新闻</title>
		<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
		<script type="text/javascript" src="ckfinder/ckfinder.js"></script>
		<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script><!--Jquery版本问题导致上传图片失败 所以换成低版本  -->
		<script type="text/javascript" src="js/jquery.form.js"></script>
		<link type="text/css" rel="stylesheet" href="style/glDatePicker.default.css">
		<script src="js/glDatePicker.js" type="text/javascript"></script>
		<script type="text/javascript" >
		$(document).ready(function(){
			$('#btn_upload').click(function(){
				alert("test");
				 var uploadUrl = "/IntroProject/admin/uploadsFiles.jsp"; //这是我自己的处理文件/图片上传的页面URL
		         var imgUrl = window.showModalDialog(uploadUrl);
		       //在upload结束后通过js代码window.returnValue=...可以将图片url返回给imgUrl变量。
		       //更多window.showModalDialog的使用方法参考

		         //  var urlObj = document.getElementById(theURLElementId);

		         //  urlObj.value = imgUrl;

		          // urlObj.fireEvent("onchange"); //触发url文本框的onchange事件，以便预览图片
		          $('#imageSrc').attr('value',imgUrl);
		          $('#image').attr('src',imgUrl);
		          alert(imgUrl);
		          
			});
			

	          $('#date_str').glDatePicker();
				$('#submit_btn').click(function(){
					if($('#date_str').attr('value')=='') {
						alert("请输入日期");
						return;
					}
					
					if($('#image_src').attr('value')=='') {
						alert("请上传图片");
						return;
					}
						
					  document.editNews.submit();
				});
		});


		function uploadImage() {  
		    $(document).ready(  
		                    function() {
		                    	alert($('#fileupload').attr('value'));
		                        var options = {  
		                            url : "<%=path%>/material!ajaxGetImage",//跳转到相应的Action  
		                            type : "POST",//提交方式  
		                            dataType : "script",//数据类型  
		                            success : function(msg) {//调用Action后返回过来的数据  
		                                alert(msg);  
		                                if (msg.indexOf("#") > 0) {  
		                                    var data = msg.split("#");  
		                                    //var data = msg.split("#");  
		                                    $("#message").html("<font color='red'>"+data[0]+data[2]+"</font>");  
		                                    $("#image_src").attr("value",data[1]);
		                                    $("#image_src2").attr("value",data[1]);
		                                    $("#showImage").html("<img src='<%=basePath%>"+data[1]+"'/><br/><input type='button' value='删除图片' id='btn_delete'> ");
		                                    $('#btn_delete').click(function(){
		                                    	alert("delete123");
		                       					$.get("admin/deleteImg",$("#form3").serializeArray(),
		                       						function(data,statusText) {
		                       							alert(data);
			                       						$("#showImage").html("");
			                       						$("#image_src").attr("value","");
			                       					 	$("#image_src2").attr("value","");
			                       					 	$("#message").html(""); 
		                       						},
		                       						"html"
		                       					);
		                       			    });
		                                } else {  
		                                    $("#message").html(msg);//在相应的位置显示信息  
		                                }  
		                            }  
		                        };  
		                        $("#form2").ajaxSubmit(options);//绑定页面中form表单的id  
		                        return false;  
		                    }
		    );  
		}  
		function test(oEvent){
			   var  e=event || oEvent;

			  //if(e.keyCode>95 && e.keyCode<106)
			  //{
			     
			   //   return true;
			   //}
			return false;

			}
		</script>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	</head>
	<s:set name="news" value="#request.news"></s:set>
	<body>
		修改新闻新闻
		<br />
		
		图片预览 <div id="showImage"></div> 
		<form id="form2" method="post" enctype="multipart/form-data"> 
 			<input id="fileupload" name="fileMaterial" type="file" /> 
 			<div id="message"><img src='<%=basePath%><s:property value="#news.imagePath" />'/></div>   
 			<input type="button" class="right-button02"onclick="uploadImage()" value="上传" /> 
		</form> 
		<s:form action="editNewsAction" id='editNews'>
			 标题:<input type="text" size="60" name="title" value="<s:property value="#news.title" />" /><br/>
			  日期:<input type="text" id="date_str" name="date_str"  onkeydown="return test(event);" value="<s:date name="#news.date" format="yyyy年MM月dd日"/>"/><br/>
			 <input type="hidden" name="image_src" value="<s:property value="#news.imagePath" />" id="image_src">
			 <input type="hidden" name="news_id" value="<s:property value="#news.id" />" id="news_id">
			 <textarea id="txt" name="content" rows="5" cols="120"><s:property value="#news.content" /></textarea>			 
			 <ckf:setupCKEditor  basePath="/IntroProject/ckfinder/"  editor="txt"/>
			<ck:replace replace="txt" basePath="/IntroProject/ckeditor/"></ck:replace>
			<br/>	
			<%--
					<textarea rows="30" cols="50" name="editor01">请输入.</textarea>
					<script type="text/javascript">
						var editor = CKEDITOR.replace('editor01');
					</script>
			--%>
		</s:form>
		 <input type="button" value="修改" id='submit_btn'/>   
		 
		 <form id="form3" > 
 			  <input type="hidden" name="image_src2" value="" id="image_src2"> 
		</form> 
	</body>
</html>
